package drds.server.sqlparser.table;

import java.util.HashMap;
import java.util.Map;

import drds.server.sqlparser.StringUtils;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class Column {

	private String tableName;
	private String columnName;
	//
	private boolean selectItem;
	private boolean where;
	private boolean groupBy;
	private boolean groupByFilter;// Having过滤
	private boolean join;

	private Map<String, Object> attributeMap = new HashMap<String, Object>();

	public Column() {

	}

	public Column(String tableName, String columnName) {
		this.tableName = tableName;
		this.columnName = columnName;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public boolean isWhere() {
		return where;
	}

	public void setWhere(boolean where) {
		this.where = where;
	}

	public boolean isSelectItem() {
		return selectItem;
	}

	public void setSelectItem(boolean selectItem) {
		this.selectItem = selectItem;
	}

	public boolean isGroupBy() {
		return groupBy;
	}

	public void setGroupBy(boolean groupBy) {
		this.groupBy = groupBy;
	}

	public boolean isGroupByFilter() {
		return groupByFilter;
	}

	public boolean isJoin() {
		return join;
	}

	public void setJoin(boolean join) {
		this.join = join;
	}

	public void setGroupByFilter(boolean groupByFilter) {
		this.groupByFilter = groupByFilter;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setName(String name) {
		this.columnName = name;
	}

	public Map<String, Object> getAttributes() {
		return attributeMap;
	}

	public void setAttributes(Map<String, Object> attributeMap) {
		this.attributeMap = attributeMap;
	}

	public int hashCode() {
		int tableHashCode = tableName != null ? StringUtils.lowerHashCode(tableName) : 0;
		int nameHashCode = columnName != null ? StringUtils.lowerHashCode(columnName) : 0;

		return tableHashCode + nameHashCode;
	}

	public boolean equals(Object o) {

		if (!(o instanceof Column)) {
			return false;
		}

		Column column = (Column) o;

		if (tableName == null) {
			if (column.getTableName() != null) {
				return false;
			}
		} else {
			if (!tableName.equals(column.getTableName())) {
				return false;
			}
		}

		if (columnName == null) {
			if (column.getColumnName() != null) {
				return false;
			}
		} else {
			if (!columnName.equals(column.getColumnName())) {
				return false;
			}
		}

		return true;
	}
}